n_gl = int(input())
nnn = n_gl
nn1 = n_gl % 100
nn2 = nnn % 100
nn3 = nnn % 1000
nn4 = n_gl % 1000
nn5 = n_gl % 10
nnn6 = n_gl % 1000
nn6= nnn6 // 100
nnn7 = n_gl % 100
nn7 = nnn7 // 10
nn8 = n_gl % 10
nn9 = n_gl // 1000

nnnn = 0
a = 0
spisok = []
def funct(a):
    n = a
    k = 0
    if a == 1:
        return 0
    if a == 2:
        return a
    if a != 2 and a != 1:
        for i in range(2,n):
            if n % i == 0:     
                k += 1
            if k == 0:
                nnnn = a
                return nnnn
            else:
                return 0
funct(nn1)
funct(nn2)
funct(nn3)
funct(nn4)
funct(nn5)
funct(nn6)
funct(nn7)
funct(nn8)
funct(nn9)
spisok2 = []
spisok2=spisok2.append(funct(nn1))
print(max(funct(nn1),funct(nn2), funct(nn3), funct(nn4), funct(nn5),funct(nn6),funct(nn7),funct(nn8),funct(nn9)))

            
